package com.niuwa.p2p.core.utils;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;

/*
 * 
 * @title MD5Util.java
 *
 * @author tennyqin
 * @version 1.0
 * @created 2015年3月25日
 */
public class MD5Util {

	public MD5Util() {
	}

	public static String hash(String input) {
		if (StringUtil.isEmpty(input)) {
			return "";
		} else {
			byte[] source;
			try {
				source = input.getBytes("UTF-8");
			} catch (UnsupportedEncodingException var10) {
				source = input.getBytes();
			}

			String result = null;
			char[] hexDigits = new char[] { '0', '1', '2', '3', '4', '5', '6',
					'7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

			try {
				MessageDigest e = MessageDigest.getInstance("MD5");
				e.update(source);
				byte[] temp = e.digest();
				char[] str = new char[32];
				int k = 0;

				for (int i = 0; i < 16; ++i) {
					byte byte0 = temp[i];
					str[k++] = hexDigits[byte0 >>> 4 & 15];
					str[k++] = hexDigits[byte0 & 15];
				}

				result = new String(str);
			} catch (Exception var11) {
				var11.printStackTrace();
			}

			return result;
		}
	}
}
